package org.pangu.test.observer;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author zhangyj
 * @date 2022/7/13 0:46
 */
public class OilSubject implements Subject {

    private List<Observer> observerList = new CopyOnWriteArrayList<>();

    @Override
    public void registerObserver(Observer observer) {
        observerList.add(observer);
    }

    @Override
    public void deleteObserver(Observer observer) {
        observerList.remove(observer);
    }

    @Override
    public void notify(Object msg) {
        for (Observer observer : observerList) {
            observer.update(msg);
        }
    }
}
